package api

import (
	"fmt"
	"net/http"

	"gitee.com/yangwencheng/vblog/apps/comment"
	"github.com/gin-gonic/gin"
)

func (h *Handler) QueryComment(ctx *gin.Context) {
	id := ctx.Query("id")
	fmt.Println(id)
	params := &comment.QueryCommentRequest{}
	res, err := h.srv.QueryComment(ctx, params)

	if err != nil {
		ctx.AbortWithError(http.StatusOK, err)
		return
	}
	ctx.JSON(http.StatusOK, res)
}

func (h *Handler) CreateComment(ctx *gin.Context) {
	id := ctx.Query("id")
	fmt.Println(id)
	params := &comment.CreateCommentRequest{}
	res, err := h.srv.CreateComment(ctx, params)

	if err != nil {
		ctx.AbortWithError(http.StatusOK, err)
		return
	}
	ctx.JSON(http.StatusOK, res)
}
func (h *Handler) ShowComment(ctx *gin.Context) {
	id := ctx.Query("id")
	fmt.Println(id)
	params := &comment.ShowCommentRequest{}
	res, err := h.srv.ShowComment(ctx, params)

	if err != nil {
		ctx.AbortWithError(http.StatusOK, err)
		return
	}
	ctx.JSON(http.StatusOK, res)
}
func (h *Handler) UpdateComment(ctx *gin.Context) {
	id := ctx.Query("id")
	fmt.Println(id)
	params := &comment.UpdateCommentRequest{}
	res, err := h.srv.UpdateComment(ctx, params)

	if err != nil {
		ctx.AbortWithError(http.StatusOK, err)
		return
	}
	ctx.JSON(http.StatusOK, res)
}
func (h *Handler) DeleteComment(ctx *gin.Context) {
	id := ctx.Query("id")
	fmt.Println(id)
	params := &comment.DeleteCommentRequest{}
	res, err := h.srv.DeleteComment(ctx, params)

	if err != nil {
		ctx.AbortWithError(http.StatusOK, err)
		return
	}
	ctx.JSON(http.StatusOK, res)
}
